package com.ethereal.petmanagement.service.impl;

import com.ethereal.petmanagement.dao.impl.UserDaoImpl;
import com.ethereal.petmanagement.dto.UserDTO;
import com.ethereal.petmanagement.service.IUserService;
import com.ethereal.petmanagement.util.PasswordUtil;

import java.util.Date;

public class UserServiceImpl implements IUserService {
    static UserDaoImpl userDao = new UserDaoImpl();
    @Override
    public void login(UserDTO userDTO) {
        UserDTO userDTO1 = userDao.findUserByUsername(userDTO);

        PasswordUtil.verify(userDTO.getPassword(), userDTO1.getPassword(), userDTO1.getSalt());
    }

    @Override
    public Boolean register(UserDTO userDTO) {
        System.out.println("service");
        userDTO.setId(PasswordUtil.generateId());
        System.out.println(userDTO.getId());
        userDTO.setSalt(PasswordUtil.generateSalt());
        System.out.println(userDTO.getSalt());
        userDTO.setCreateTime(new Date());
        userDTO.setPassword(PasswordUtil.encrypt(userDTO.getPassword(), userDTO.getSalt()));
        System.out.println(userDTO.getPassword());
        System.out.println("ok");
        return userDao.insertUser(userDTO);
    }
}
